<html>
<head>
<meta charset="UTF-8">
<title>系统部署信息新增</title>
	<link id="easyuiTheme" href="../../static/easyui/themes/bootstrap/easyui.css" rel="stylesheet" type="text/css"/>
	<link href="../../static/easyui/themes/icon.css" rel="stylesheet" type="text/css"/>
	<link href="../../static/css/esaas-easyui-add.css" rel="stylesheet" type="text/css"/>
	<script src="../../static/easyui/jquery.min.js" type="text/javascript"></script>
	<script src="../../static/easyui/jquery.cookie.js" type="text/javascript"></script>
	<script src="../../static/easyui/ui-theme.js" type="text/javascript"></script>
	<script src="../../static/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../static/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.util.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.jquery.ajax.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.easyui.util.js" type="text/javascript"></script>
	<script src="../../ffres/dict/all.js" type="text/javascript"></script>
	<a href="" target="_blank" id="commonLink" name="commonLink"></a>
</head>
<body class="easyui-layout" overflow="auto">
<div data-options="region:'center',split:false">
	<form id="ff" method="post">
		<div class="esaas-info-title">应用信息<hr /></div>
		<table class="esaas-info-add-table">
			<tr hidden="true">
				<td width="15%" align="right">应用部署标识：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
									   name="appDeployId" data-options="required:true"
									   style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr>
				<td width="15%" align="right">应用代码：</td>
				<td width="35%"><input class="easyui-textbox" id="appCode" type="text" buttonText="选择应用"
									   name="appCode" data-options="required:true"
									   style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right">应用名称：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
									   name="appName" id="appName" data-options="required:true"
									   style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr>
				<td width="15%" align="right">应用版本：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
									   name="appVersion" data-options="required:true"
									   style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right">应用排列顺序：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
									   name="appOrder" data-options="required:true"
									   style="width: 100%; height: 25px;"></input></td>
			</tr>
		</table>
		<div class="esaas-info-title">服务器信息<hr /></div>
		<table class="esaas-info-add-table">
			<tr>
				<td width="15%" align="right">服务器名称：</td>
				<td width="35%"><input class="easyui-textbox" type="text" buttonText="选择服务器"
									   name="ecsName" id="ecsName" data-options="required:true"
									   style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right">服务器IP：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
									   name="ecsIp" data-options="required:true"
									   style="width: 100%; height: 25px;"></input></td>

			</tr>
			<tr>
				<td width="15%" align="right">服务器登陆用户：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
									   name="ecsLoginUser" data-options="required:true"
									   style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right">服务器登陆密码：</td>
				<td width="35%"><input class="easyui-textbox" type="password"
									   name="ecsLoginPwd" data-options="required:true"
									   style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr>
				<td width="15%" align="right">所在位置：</td>
				<td width="35%"><select class="easyui-combobox"
										id="ecsRegion" name="ecsRegion"
										style="width: 100%; height: 25px;"
										data-options="required:true,editable:false,valueField:'enname',textField:'cnname',data:ECS_REGION">
				</select></td>
			</tr>
		</table>
		<div class="esaas-info-title">部署信息<hr /></div>
		<table class="esaas-info-add-table">
			<tr>
				<td width="15%" align="right">应用部署目录：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
									   name="appDeployPath" id="appDeployPath" data-options="required:true"
									   style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right">应用日志目录：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
									   name="appLogPath" id="appLogPath" data-options="required:true"
									   style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr>
				<td width="15%" align="right">应用端口：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
									   name="appPort" data-options="required:true"
									   style="width: 100%; height: 25px;"></input></td>

			</tr>
			<tr hidden="true">
				<td width="15%" align="right">操作时间：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
									   name="operTime" data-options="required:false"
									   style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right">操作人：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
									   name="operUserid" data-options="required:false"
									   style="width: 100%; height: 25px;"></input></td>
			</tr>
		</table>
	</form>
	<form id="fileUpload" method="post" enctype="multipart/form-data" action="../../api/sys/deploy/info/upload">
		<table class="esaas-info-add-table">
			<tr>
				<td width="15%" align="right">war包上传：</td>
				<td width="35%"><input  class="easyui-filebox" id="file" name="file" data-options="required:false,buttonText:'选择文件'" style="width: 100%;height: 25px" /></td>
				<td ><a href="javascript:void(0)" class="easyui-linkbutton" onclick="UploadFile()" id="uploadButton">上传</a></td>
			</tr>
			<tr>
				<td width="15%" align="right"></td>
				<td><label id="fileName" /></td>
			</tr>
		</table>
		<div>
		</div>
	</form>
	<div style="text-align: center; padding: 15px">
		<a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()">&nbsp;保&nbsp;存&nbsp;</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" onclick="closeForm()">&nbsp;关&nbsp;闭&nbsp;</a>
	</div>
</div>


	<script>
		var file;
		var deployData;

		$(function() {
			addTitle("手动部署")
			$("#appCode").textbox({
				onClickButton:function (){
					var subsCode = $.getUrlParam("subsCode");
					JLEUtil.createModalWinCustomSize('', 'popSysAppsInfoChoice.html?subsCode=' + subsCode,0.8,0.8);
				}
			})

			$("#ecsName").textbox({
				onClickButton:function (){
					var subsCode = $.getUrlParam("subsCode");
					JLEUtil.createModalWinCustomSize('', 'popSysEscInfoChoice.html?subsCode=' + subsCode+"&bpmId=111",0.8,0.8);
				}
			})
			$('#uploadButton').linkbutton('disable')
			//选择文件时，检验是否为war包，并显示文件详细信息
			$('#file').filebox({
				onChange:function (newValue,oldValue){
					//获取上传文件控件内容
					//filebox_file_id_1 这个ID 是easyui 自己创建的input 便签. 这里面是真正保存文件的地方.
					//如果创建了多个filebox  那么后面的ID 就是filebox_file_id_2,filebox_file_id_3.
					file = document.getElementById('filebox_file_id_2').files[0];
					// 判断控件中是否存在文件内容，如果不存在，弹出提示信息，阻止进一步操作
					if (file == null) { alert('错误，请选择文件'); return; }
					//获取文件名称
					var fileName = file.name;
					//获取文件类型名称
					var file_typename = fileName.substring(fileName.lastIndexOf('.'), fileName.length);
					//这里限定上传文件文件类型必须为.war，如果文件类型不符，提示错误信息
					if (file_typename == '.war') {
						//计算文件大小
						var fileSize = 0;
						//如果文件大小大于1024字节X1024字节，则显示文件大小单位为MB，否则为KB
						if (file.size > 1024 * 1024) {
							fileSize = Math.round(file.size * 100 / (1024 * 1024)) / 100;

							if (fileSize > 100) {
								alert('错误，文件超过100MB，禁止上传！');
								return;
							}
							fileSize = fileSize.toString() + 'MB';
						} else {
							fileSize = (Math.round(file.size * 100 / 1024) / 100).toString() + 'KB';
						}
						//将文件名和文件大小显示在前端label文本中
						document.getElementById('fileName').innerHTML = "<span style='color:Blue'>文件名: " + file.name + ',大小: ' + fileSize + "</span>";
						$('#uploadButton').linkbutton('enable')
					}
					else {
						alert("文件类型错误");
						//将错误信息显示在前端label文本中
						$('#uploadButton').linkbutton('disable')
						document.getElementById('fileName').innerHTML = "<span style='color:Red'>错误提示:上传文件应该是.war后缀而不应该是" + file_typename + ",请重新选择文件</span>"
					}
				}
			})

		});
		//上传文件
		function UploadFile(){
			$('#fileUpload').form('submit',{
				url: '../../api/sys/deploy/info/upload',
				onSubmit: function(){
					document.getElementById('fileName').innerHTML = "<span style='color:Blue'>上传中，请等待完成！</span>";
				},
				success: function(result){
					document.getElementById('fileName').innerHTML = "<span style='color:Blue'>上传完成！</span>";
					$('#appDeployPath').textbox('setValue',"/WarFile/"+file.name.substring(0,file.name.length));
					$('#appLogPath').textbox('setValue',"/agent/"+file.name.substring(0,file.name.length-4)+"/logs");
					alert(result)
				}
			});
		}

		function onChooseApp(data){
			deployData = data;
			if (data){
				$('#ff').form('load',data)
			}
		}
		function onChooseOrgName(data){
			if (data){
				$('#ff').form('load', data)
			}
		}

		function submitForm() {
			// if (!$('#ff').form('validate'))
			// 	return;
			var jsonData = $("#ff").serializeJson();
			var subsCode = $.getUrlParam("subsCode");
			jsonData.subsCode = subsCode;
			jsonData.appId = deployData.appId;
			jsonData.appName = $('#appCode').textbox('getValue');
			jsonData.appCnname = $('#appName').textbox('getValue');
			jsonData.ecsId = deployData.ecsId;
			$.restfulPostJson('../../api/sys/deploy/info', jsonData, function(data) {
				alert("正在上传部署中");
			});
		};



		function closeForm() {
			$.messager.confirm('确认','您确认想要关闭页面吗？',function(r){
				if (r){
					window.parent.close();
				}
			});
		}
	</script>
</body>
</html>